package com.wuchao.util;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * @Author wuchao66
 * @Date 2023/10/11 11:13
 * @PackageName:com.wuchao.util
 * @ClassName: SysInterceptors
 * @Description: TODO
 * @Param
 * @Version 1.0
 */
public class SysInterceptors extends HandlerInterceptorAdapter
{
    public boolean preHandle(
            HttpServletRequest request
            , HttpServletResponse response,
            Object handler) throws Exception {
        HttpSession session = request.getSession();
        Object user = session.getAttribute("user");
        if(user==null||user==""){
            System.out.println("被拦截");
            response.sendRedirect(request.getContextPath()+"/index.jsp");
            return false;//${pageContext.request.contextPath}
        } System.out.println("不拦截");
            return true;
    }
}
